using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class report : System.Web.UI.Page
{
    TemplateManager templateManager;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Request["id"]))
        {
            Response.Write("Lacks paramerter");
            Response.Redirect("Login.aspx");
            //return;
        }
        /*IDbConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["SurveyConnectionString"].ConnectionString);
        using(conn)
        {
            conn.Open();           
        }
        conn.Close();*/
        if (Session["answers"] == null)
            Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["RedirectUrl"]);
            //Response.Redirect("Login.aspx");
        IEnumerable<Part> parts = (IEnumerable<Part>)Session["parts"];
        IEnumerable<Answer> answers = (IEnumerable<Answer>)Session["answers"];
        if (parts != null && answers != null)
        {
            ReportBuilder reporBuilder = new ReportBuilder(parts, answers);
            Control control = reporBuilder.generateReport();
            PlaceHolder1.Controls.Add(control);
            lbSuccess.Text = reporBuilder.SuccessScore.ToString("F3");
            lbPresure.Text = reporBuilder.PressureScore.ToString("F3");
            lbImportance.Text = reporBuilder.ImportanceScore.ToString("F3");
            lbActivity.Text = reporBuilder.ActivityScore.ToString("F3");
            if (lbActivity.Text.Equals("0"))
            {
                lbActivity.Text = "Not applicable. You did not attempt to put any principles into play";
            }

            lbSces_avdc.Text = reporBuilder.Sces_avdc.ToString("F3");
            lbPres_avdc.Text = reporBuilder.Pres_avdc.ToString("F3");
            lbAty_avdc.Text = reporBuilder.Aty_avdc.ToString("F3");
            lbImptc_avdc.Text = reporBuilder.Imptc_avdc.ToString("F3");
            if (lbAty_avdc.Text.Equals("0"))
            {
                lbAty_avdc.Text = "Not applicable. You did not attempt to put any principles into play";
            }
            Participant participant = (Participant)Session[FormContract.USER_REF];
            templateManager = new TemplateManager(reporBuilder, participant.EmailAddress);
        }
        
    }
    protected void btDownload_Click(object sender, EventArgs e)
    {
        templateManager.Download();
    }
}
